home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1993-02-25 | 3.3 KB | 140 lines |
- '-----------------------------------------------------------------------------
- ' Sample Double Buffering example
- ' By Fran�ois Lionet
- ' AMOS (c) Europress Software 1990/91
- '-----------------------------------------------------------------------------
- '
- ' This example show the use of the new musical instructions
- ' SAM SWAP and SAM SWAPPED to play samples of any length
- ' directly from the disc.
- ' This example will only work with a hard-drive, or a CD-ROM
- ' player. Well, it may be possible to play at a very low
- ' rate, like 3000 Herz, with a disgusting result, from a floppy.
- '
- ' First thing to do: create or grab a big sample, and save it
- ' with the name "SAMPLE.SAM"
- '
- '-----------------------------------------------------------------------------
- '
- ' First, we must reserve two memory banks in CHIP RAM. Two, because
- ' we are double buffering. No need to choose banks too long. The
- ' longer the banks, the longer the delay between each load will
- ' be.
- ' You can start with as little as 8 K per buffer.
- '
- LBANK=1024*8
- '
- ' Lets reserve.
- '
- Reserve As Chip Work 10,LBANK
- Reserve As Chip Work 11,LBANK
- '
- ' Lets define the voices used to play the sample.
- ' First, the bitpattern, then the voice used to test the swap.
- V=%11 : VX=0
- '
- ' Replay frequeny
- '
- FREQ=10000
- '
- ' Open the sample, with a simple OPEN IN.
- '
- F$="Sample.Sam"
- '
- Open In 1,F$
- '
- ' Get the length of the file, once for all. You should avoid
- ' the use of =POF and =LOF while you are playing the sample, as
- ' they move the head.
- LSAM=Lof(1)
- '
- ' Maxximum volume!
- '
- Volume 63
- '
- ' Lets load the first part of the sample in the first bank,
- ' with the new fabulous instruction, SLOAD
- '
- Sload 1 To Start(10),LBANK
- '
- ' You must launch the sample with SAM RAW. This instruction
- ' set the replay rate for all the sample.
- '
- Sam Raw V,Start(10),LBANK,FREQ
- '
- ' Calculate the remaining length.
- '
- LSAM=LSAM-LBANK
- '
- ' Flipping buffer indicator.
- '
- PSAM=1
- '
- ' This is the sample-swapping loop. Of course, this loop
- ' mainly does nothing. In a program, you can call you graphic output
- ' routines, and just check for the sample-swapping from time
- ' to time, with a specific procedure...
- '
- ' While we have something to load...
- '
- While LSAM>0
- '
- Repeat
- '
- ' A small delay loop when you press a mousekey, to
- ' simulate an out-of-sync : the sample will stop for a
- ' moment.
- ' This could happend if you do not check for the sample-swapping
- ' frequently enough...
- '
- While Mouse Key : Wend
- '
- ' Nice multitask wait.
- Multi Wait
- '
- ' The loop will exit when you can load another
- ' part of the sample...
- '
- P=Sam Swapped(VX)
- '
- Until P
- '
- ' How long left to load?
- '
- LLOAD=Min(LSAM,LBANK)
- '
- ' Lets load the bits.
- Sload 1 To Start(10+PSAM),LLOAD
- '
- ' Initialise the newly loaded buffer.
- '
- If P=-1
- '
- ' We are still synchronised, we can do a nice
- ' sample-swap.
- '
- Sam Swap V To Start(10+PSAM),LLOAD
- '
- Else
- '
- ' Oops, to late! We have to restart the sample.
- '
- Sam Raw V,Start(10+PSAM),LLOAD,FREQ
- '
- End If
- '
- ' Count how much left to load.
- '
- LSAM=LSAM-LLOAD
- '
- ' Flip the buffers.
- '
- PSAM=1-PSAM
- '
- ' Exit if any key pressed.
- If Inkey$<>"" : Sam Stop : Exit : End If
- '
- Wend
- '
- ' Close the file.
- Close